package com.github.fork.config;

import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
import org.springframework.beans.factory.config.YamlProcessor;
import org.springframework.beans.factory.config.YamlPropertiesFactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;

/**
 * @author Jerry Liu
 * @since 2017/3/14
 */
@Configuration
@ComponentScan("com.github.fork.service")
public class PropertiesConfig {

    @Bean
    public static PropertyPlaceholderConfigurer props() {
        PropertyPlaceholderConfigurer props = new PropertyPlaceholderConfigurer();
        YamlPropertiesFactoryBean yaml = new YamlPropertiesFactoryBean();
        yaml.setResources(new ClassPathResource("application.yml"));
        yaml.setResolutionMethod(YamlProcessor.ResolutionMethod.FIRST_FOUND);
        props.setProperties(yaml.getObject());
        //props.setIgnoreResourceNotFound(true);
        props.setIgnoreUnresolvablePlaceholders(true);
        return props;
    }
}
